package com.atguigu.linklist;

public class TheEntranceOfRing {
    public static ListNode findTheEntrance(ListNode head){
        if(head==null) return null;
        if(head.next==null &&head.next.next==null) return head;
        ListNode fast=head.next.next;
        ListNode slow=head.next;
        while(fast!=null || fast!=slow){
            fast=fast.next.next;
            slow=slow.next;
        }
        if(fast==null) return null; //无环
        fast=head;
        while(fast!=slow){
            fast=fast.next;
            slow=slow.next;
        }
        return fast;
    }
}
